﻿using Microsoft.AspNetCore.Mvc;
using SportsPlatform.Base;
using SportsPlatform.Dto.SportBusiness.Employee;
using SportsPlatform.Dto.SportBusiness.CompetitionGroupingInfo;
using SportsPlatform.Dto.SportBusiness.Team;
using SportsPlatform.Query.SportBusiness.CompetitionGroupingInfo;
using SportsPlatform.Query.SportBusiness.Employee;
using SportsPlatform.Query.SportBusiness.Team;
using SportsPlatform.SportBusiness.ISportBusiness;
using SportsPlatform.WeChat.IWeChat;
using System.Collections.Generic;
using System.Threading.Tasks;
using SportsPlatform.Dto.WeChat.Me;
using SportsPlatform.Query.WeChat;
using SportsPlatform.Query.SportBusiness.Feedback;
using SportsPlatform.SportBusiness.SportBusiness;
using Microsoft.AspNetCore.Authorization;
using SportsPlatform.Filters;
using Polly.Caching;
using Nest;
using System;

namespace SportsPlatform.Controllers
{
    /// <summary>
    /// 移动端我的页面控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [AllowAnonymousAttribute]
    public class WeChatMeController : SportsPlatformControllerBase
    {
        #region 私有变量

        private IMeService _meService;
        private ITeamService _teamService;
        private IEmployeeService _employeeService;
        private ICompetitionGroupingInfoService _competitionGroupingInfoService;

        #endregion

        #region 构造函数

        /// <summary>
        /// 
        /// </summary>
        /// <param name="meService"></param>
        /// <param name="teamService"></param>
        /// <param name="employeeService"></param>
        /// <param name="competitionGroupingInfoService"></param>
        public WeChatMeController(IMeService meService,
            ITeamService teamService,
            IEmployeeService employeeService,
            ICompetitionGroupingInfoService competitionGroupingInfoService)
        {
            _meService = meService;
            _teamService = teamService;
            _employeeService = employeeService;
            _competitionGroupingInfoService = competitionGroupingInfoService;
        }

        #endregion

        #region 公共接口API

        #region MeInfo

        /// <summary>
        /// 获取对应标识用户信息
        /// </summary>
        /// <param name="query">标识</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<WeCahtMeEmployeeDto>> GetEmployeeById([FromBody] GetEmployeeByIdQuery query)
        {
            return await _meService.GetByIdToEmployee(query);
        }

        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="query">更新传入参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<EmployeeDto>> UpdateEmployee([FromBody] UpdateEmployeeQuery query)
        {
            return await _meService.UpdateEmployee(query);
        }

        /// <summary>
        /// 团队列表查询
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<TeamByUserListDto>> GetTeamList([FromBody] TeamByUserListQuery Query)
        {
            return await _teamService.GetTeamList(Query);
        }

        /// <summary>
        /// 获取团队成员列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<WeChatTeamDto>> GetMeTeamEmployee([FromBody] GetMeTeamEmployeeQuery query)
        {
            return await _meService.GetTeams(query);
        }

        /// <summary>
        /// 获取用户报名总数
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<int>> GetRegisterCount([FromBody] GetEmployeeRegisterQuery query)
        {
            return await _meService.GetRegisterCount(query);
        }

        /// <summary>
        /// 获取赛事总条数
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<int>> GetCompetitionCount([FromBody] GetEmployeeRegisterQuery query)
        {
            return await _meService.GetCompetitionCount(query);
        }

        #endregion

        #region Team
        /// <summary>
        /// 添加团队
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> AddTeam([FromBody] AddTeamQuery Query)
        {
            return await _teamService.AddTeam(Query);
        }

        /// <summary>
        /// 添加成员
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> AddTeamUser([FromBody] AddEmployeeQuery Query)
        {
            return await _employeeService.AddTeamUser(Query);
        }

        /// <summary>
        /// 通过用户id获取最新创建的团队名称
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<string>> GetByEmloyeeId([FromBody] GetEmployeeRegisterQuery query)
        {
            return await _meService.GetByEmloyeeId(query);
        }
        #endregion

        #region CompetitionGroupingInfo 
        /// <summary>
        /// 我的赛事
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<CompetitionGroupingInfoByUserListDto>> GetCompetitionGroupingInfoByUserList([FromBody] CompetitionGroupingInfoByUserListQuery Query)
        {
            return await _competitionGroupingInfoService.GetCompetitionGroupingInfoByUserList(Query);
        }

        /// <summary>
        /// 我的赛事详情
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<List<CompetitionGroupingInfoByUserDetailsDto>>> GetCompetitionGroupingInfoByUserDetails([FromBody] CompetitionGroupingInfoByUserDetailsQuery Query)
        {
            return await _competitionGroupingInfoService.GetCompetitionGroupingInfoByUserDetails(Query);
        }

        /// <summary>
        /// 比赛成绩
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<CompetitionGroupingInfoByUserAchievementDto>> GetCompetitionGroupingInfoByUserAchievement([FromBody] CompetitionGroupingInfoByUserAchievementQuery Query)
        {
            return await _competitionGroupingInfoService.GetCompetitionGroupingInfoByUserAchievement(Query);
        }

        /// <summary>
        /// 历史成绩
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<CompetitionGroupingInfoByUserAchievementListDto>> GetCompetitionGroupingInfoByUserHistoricalAchievement([FromBody] CompetitionGroupingInfoByUserAchievementListQuery Query)
        {
            return await _competitionGroupingInfoService.GetCompetitionGroupingInfoByUserHistoricalAchievement(Query);
        }

        #endregion

        #region Feedback

        /// <summary>
        /// 添加意见反馈
        /// </summary>
        /// <param name="addFeedbackQuery">传入参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> AddFeedback([FromBody] AddFeedbackQuery addFeedbackQuery)
        {
            return await _meService.AddFeedbackStart(addFeedbackQuery);
        }

        #endregion



        #endregion
    }
}
